package com.lywz.biz.common.bean;

import com.lywz.biz.common.util.BizConstants;
import com.lywz.core.bean.BeanFactory;
import com.lywz.core.bean.BeanName;
import com.lywz.core.bean.SpringManager;


/**
 * 业务逻辑层的bean工厂
 * 
 * @author Lionel pang
 * @date 2010-3-16
 */
public class BizBeanFactory {

    // 当前势力
    private static BizBeanFactory _beanFachtory;

    // 核心bean管理工厂
    private BeanFactory _coreBeanFactory;

    private BizBeanFactory() {
        _coreBeanFactory = new SpringManager(BizConstants.bizSpringConfigFile);
    }

    public static BizBeanFactory getInstance() {
        if (_beanFachtory == null) {
            synchronized (BizBeanFactory.class) {
                if (_beanFachtory == null) {
                    _beanFachtory = new BizBeanFactory();
                }
            }
        }

        return _beanFachtory;
    }

    @SuppressWarnings("unchecked")
    public <T> T getBean(BeanName beanNameEnum) {
        return (T) _coreBeanFactory.getBean(beanNameEnum.getName());
    }
    
    @SuppressWarnings("unchecked")
    public <T> T getBean(String beanName) {
        return (T) _coreBeanFactory.getBean(beanName);
    }
}
